import logging
import time
from functools import wraps


def timethis(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        start = time.time()
        result = func(*args, **kwargs)
        end = time.time()
        print(func.__name__, end - start)
        return result

    return wrapper





@timethis
def countdown(n):
    """
    counts down
    """
    while n > 0:
        n -= 1


countdown(100000)
print(countdown.__name__)
print(countdown.__doc__)
print(countdown.__annotations__)


def logged(level, name=None, message=None):
    def decorate(func):
        logname = name if name else func.__module__
        log = logging.getLogger(logname)
        logmsg = message if message else func.__name__

        @wraps(func)
        def wrapper(*args, **kwargs):
            log.log(level, logmsg)
            return func(*args,**kwargs)
        return wrapper
    return decorate

def outer(x):
    def inner():
        return x
    return inner

def calc_sum(lst):
    def sec_sum():
        return sum(lst)
    return sec_sum #此时sec_sum函数不能移到calc_sum的外部


